]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensions-tool/create: Optionally include prefs
authorFlorian Müllner <fmuellner@gnome.org>
Sun, 13 Aug 2023 23:08:56 +0000 (01:08 +0200)
committerMarge Bot <marge-bot@gnome.org>
Sat, 26 Aug 2023 17:10:28 +0000 (17:10 +0000)
We currently only create boilerplate code for the actual
extension. Now that libadwaita has largely standardized
preference UIs, it makes sense to allow creating the
prefs.js boilerplate as well.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2889>

po/POTFILES.skip
subprojects/extensions-tool/man/gnome-extensions.txt
subprojects/extensions-tool/src/command-create.c
subprojects/extensions-tool/src/gnome-extensions-tool.gresource.xml
subprojects/extensions-tool/src/templates/prefs.js [new file with mode: 0644]

index 36fe39be55bf750be1bd587cfe124ee62eabe4af..02aa312ff21dd8e00c7bd1f79c6da49615a050b5 100644 (file)
@@ -2,4 +2,5 @@ data/org.gnome.Shell@wayland.service.in
 data/org.gnome.Shell@x11.service.in
 js/ui/init.js
 subprojects/extensions-tool/src/templates/indicator/extension.js
+subprojects/extensions-tool/src/templates/prefs.js
 subprojects/extensions-tool/src/templates/quick-settings/extension.js
index cd55191fbf805af89a86c8fbc710edfad415ffbc..0d6b5eafff51b9746ff2d73a7e426848ba18a0e9 100644 (file)
@@ -137,6 +137,9 @@ Creates a new extension from a template.
   *--template*='TEMPLATE':::
     Use 'TEMPLATE' as base for the new extension
 
+  *--prefs*:::
+    Include a prefs.js template
+
   *-i*:::
   *--interactive*:::
     Prompt for any extension metadata that hasn't been provided
index 879047cb25d5f81ed51fe0ac28e53a575719e2d6..1f65b265d3faf7a9fba9cc4f3a31d38232db049c 100644 (file)
@@ -253,6 +253,23 @@ copy_extension_template (const char *template, GFile *target_dir, GError **error
   return TRUE;
 }
 
+static gboolean
+copy_prefs_template (GFile *target_dir, GError **error)
+{
+  g_autoptr (GFile) target = NULL;
+  g_autoptr (GFile) source = NULL;
+  g_autofree char *uri = NULL;
+
+  uri = g_strdup ("resource://" TEMPLATES_PATH "/prefs.js");
+  source = g_file_new_for_uri (uri);
+  target = g_file_get_child (target_dir, "prefs.js");
+
+  if (!g_file_copy (source, target, G_FILE_COPY_TARGET_DEFAULT_PERMS, NULL, NULL, NULL, error))
+    return FALSE;
+
+  return TRUE;
+}
+
 static gboolean
 launch_extension_source (GFile *dir, GError **error)
 {
@@ -282,7 +299,8 @@ create_extension (const char *uuid,
                   const char *description,
                   const char *gettext_domain,
                   const char *settings_schema,
-                  const char *template)
+                  const char *template,
+                  gboolean    prefs)
 {
   g_autoptr (GFile) dir = NULL;
   g_autoptr (GError) error = NULL;
@@ -320,6 +338,12 @@ create_extension (const char *uuid,
       return FALSE;
     }
 
+  if (prefs && !copy_prefs_template (dir, &error))
+    {
+      g_printerr ("%s\n", error->message);
+      return FALSE;
+    }
+
   if (!launch_extension_source (dir, &error))
     {
       g_printerr ("%s\n", error->message);
@@ -481,6 +505,7 @@ handle_create (int argc, char *argv[], gboolean do_help)
   g_autofree char *gettext_domain = NULL;
   g_autofree char *settings_schema = NULL;
   g_autofree char *template = NULL;
+  gboolean prefs = FALSE;
   gboolean interactive = FALSE;
   gboolean list_templates = FALSE;
   GOptionEntry entries[] = {
@@ -508,6 +533,9 @@ handle_create (int argc, char *argv[], gboolean do_help)
       .arg = G_OPTION_ARG_STRING, .arg_data = &template,
       .arg_description = _("TEMPLATE"),
       .description = _("The template to use for the new extension") },
+    { .long_name = "prefs",
+      .arg = G_OPTION_ARG_NONE, .arg_data = &prefs,
+      .description = _("Include prefs.js template") },
     { .long_name = "list-templates",
       .arg = G_OPTION_ARG_NONE, .arg_data = &list_templates,
       .flags = G_OPTION_FLAG_HIDDEN },
@@ -568,5 +596,5 @@ handle_create (int argc, char *argv[], gboolean do_help)
       return 1;
     }
 
-  return create_extension (uuid, name, description, gettext_domain, settings_schema, template) ? 0 : 2;
+  return create_extension (uuid, name, description, gettext_domain, settings_schema, template, prefs) ? 0 : 2;
 }
index 4a64c61956f9e907c8f8082bf40dfac547c1ce70..c81b4bc9af86f7740bd4e81502524e244c5881d6 100644 (file)
@@ -7,6 +7,7 @@
     <file>templates/indicator/stylesheet.css</file>
     <file>templates/plain/extension.js</file>
     <file>templates/plain/stylesheet.css</file>
+    <file>templates/prefs.js</file>
     <file>templates/quick-settings.desktop</file>
     <file>templates/quick-settings/extension.js</file>
     <file>templates/quick-settings/stylesheet.css</file>
diff --git a/subprojects/extensions-tool/src/templates/prefs.js b/subprojects/extensions-tool/src/templates/prefs.js
new file mode 100644 (file)
index 0000000..3651b6a
--- /dev/null
@@ -0,0 +1,44 @@
+/* prefs.js
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+import Adw from 'gi://Adw';
+import GObject from 'gi://GObject';
+
+import {ExtensionPreferences, gettext as _} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
+
+const MyPreferencesWidget = GObject.registerClass(
+class MyPreferencesWidget extends Adw.PreferencesGroup {
+    constructor() {
+        super({
+            title: _('Section'),
+        });
+
+        this.add(new Adw.SwitchRow({
+            title: _('Title'),
+            subtitle: _('Subtitle'),
+            active: true,
+        }));
+    }
+});
+
+export default class MyPreferences extends ExtensionPreferences {
+    getPreferencesWidget() {
+        return new MyPreferencesWidget();
+    }
+}
+